<template>
      <!-- 底部订单栏 -->
    <div class="Check-Bottom-Bar">
        <div class="imgbutt_bottbombar">
            <div  class="nn_k" @click="cilck_Bottombar">
                <img src="@/assets/img/cart/gx.png" alt="" :class="{a:!isTuer}">
                 <img src="@/assets/img/cart/wgx.png" alt="" :class="{a:isTuer}">
                 <span class="data_bottombar">全部</span>
            </div>
            <div class="totalPrice">合计：{{totalPrice}}</div>
        </div>
        <div class="caculate">
            结算({{totalPrice_count}})
        </div>
    </div>
</template>

<script>

import Hub from '@/common/Hub.js'
export default {
    name:"CheckBottomBar",
    data() {
        return {
            isTuer:true
        }
    },
    computed:{
        totalPrice(){
            return '￥' + this.$store.state.cartList.filter(item =>{
                return item.checked
            }).reduce((preValue,item) =>{
                return preValue+ item.price * item.count
            },0).toFixed(2)
        },
        totalPrice_count(){
            return this.$store.state.cartList.filter(item =>{
                return item.checked
            }).length
        },
       
    },
    methods:{
         receive:function() {
            Hub.$on('all_select',(val)=>{
                this.isTuer=val
                console.log(val);
            })
            
        },
        cilck_Bottombar(){
            this.isTuer=!this.isTuer
              for(let i = 0;i<this.$store.state.cartList.length;i++){
                  if(this.$store.state.cartList[i].checked!=this.isTuer){
                    this.$store.state.cartList[i].checked=this.isTuer
                  }
           
            }
        }
    },
     mounted:function(){
    //   执行该方法
      this.receive();
  }
}
</script>

<style scoped>
.a{
    display: none;
}
.Check-Bottom-Bar{
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background-color: rgb(212, 207, 207);
    margin-bottom: 49px;
    color: rgb(31, 29, 29);
}
.imgbutt_bottbombar img{
    width: 7%;
    padding-top: 5px;
    margin-left: 5px;
}
.imgbutt_bottbombar .nn_k{
    position: relative;
    height: 44px;
}
.data_bottombar{
    position: absolute;
    left: 40px;
    display: inline-block;
    height: 44px;
    line-height: 44px;
    padding-bottom: 5px;
}
.totalPrice{
    position: absolute;
    left: 77px;
    top: 13px;
    
}
.caculate{
    height: 40px;
    width: 120px;
    position: absolute;
    right: 0px;
    top: 0px;
    text-align: center;
    line-height: 40px;
    background-color: rgb(233, 104, 104);
    color: #fff;
}
</style>